package cn.sunlelin.educationserver.controller;

import cn.sunlelin.educationserver.entity.Poster;
import cn.sunlelin.educationserver.service.PosterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class PosterController {
    @Autowired
    private PosterService posterService;

    @PostMapping("/poster/createPoster")
    public Map<String, Object> createPoster(@RequestBody Poster poster) {
        Map<String, Object> map = new HashMap<>();
        if (posterService.createPoster(poster)) {
            map.put("code", 200);
            map.put("msg", "添加海报成功");
            map.put("dataobject", null);
        } else {
            map.put("code", 500);
            map.put("msg", "添加海报失败");
            map.put("dataobject", null);
        }
        return map;
    }
    @PostMapping("/poster/updatePoster")
    public Map<String, Object> updatePoster(@RequestBody Poster poster) {
        Map<String, Object> map = new HashMap<>();
        if (posterService.updatePoster(poster)) {
            map.put("code", 200);
            map.put("msg", "修改海报成功");
            map.put("dataobject", null);
        } else {
            map.put("code", 500);
            map.put("msg", "修改海报失败");
            map.put("dataobject", null);
        }
        return map;
    }

    @GetMapping("/poster/selectPosterAll")
    public Map<String, Object> selectPosterAll() {
        Map<String, Object> map = new HashMap<>();
        List<Poster> posterList=posterService.selectPosterAll();
        map.put("code", 200);
        map.put("msg", "查询全部海报成功");
        map.put("dataobject", posterList);
        return map;
    }

    @GetMapping("/poster/deletePost/{posterId}")
    public Map<String, Object> deletePost(@PathVariable Integer posterId) {
        Map<String, Object> map = new HashMap<>();
        if (posterService.deletePost(posterId)) {
            map.put("code", 200);
            map.put("msg", "删除海报成功");
            map.put("dataobject", null);
        } else {
            map.put("code", 500);
            map.put("msg", "删除海报失败");
            map.put("dataobject", null);
        }
        return map;
    }
}
